#include "CommonFunc.h"
#include <time.h>

#include <d3dx9.h>
enum
{
	R,G,B
};
unsigned GetMagicColor()
{
	static short col[3] = {255,100,200};
	static int flag[3] = {-1,-1,1};

	static int i = 0;
	
	if (i >= 2)
		i  = 0;
	i++;

	if (col[i] > 255)
		flag[i] = -1;
	if (col[i] < 100)
		flag[i] = 1;

	col[i] += flag[i];

	unsigned ret = (((BYTE)1)|(((WORD)(BYTE)col[B]<<8)|((DWORD)((BYTE)col[G])<<16))|(((DWORD)(BYTE)col[R])<<24));
	
	return ret;
}

unsigned GetColor()
{
	static short col[3] = {255,0,0};

	static clock_t start = clock();
	clock_t curTime = clock();

	int d = curTime - start;
	if (curTime - start < 5)
	{
		unsigned ret = (0xff << 24 | col[R]<<16 | col[G]<<8 | col[B]);
		return ret;
	}
	start = curTime;

	static int flag = 1;

	static int i = B;

	const short delta = 3;

	col[i] += flag * delta;
	if (col[i] > 255)
	{
		col[i] = 255;
		i --;
		flag = -1;
		if (i < R)
			i = B;
	}

	if (col[i] < 0)
	{
		col[i] = 0;
		i --;
		flag = 1;
		if (i < R)
			i = B;
	}

	unsigned ret = (0xff << 24 | col[R]<<16 | col[G]<<8 | col[B]);

	RR color(col[R],col[G],col[B]);

	return ret;
}
